import pygame as SDL
from pygame.locals import *
import os,sys
import pENGINE,pACTORS

class Chase:
    def state(self,args):
        ball = args['ball']
        paddle = args['paddle']
        
        #if the ball is on the player's side of the screen
        #it Pushes the Evade state onto the AIStateMachine.
        #This gives off the appearence as if the enemy paddle
        #is preparing for the ball to bounce back.
        if ball.x < 170: paddle.state.push(Evade())
        
        
        #if the ball is going down, the enemy paddle goes down
        #if the ball is going up, the enemy paddle goes up
        if ball.y > (paddle.y+20):
            paddle.vDown()
            
        elif ball.y < (paddle.y+20):
            paddle.vUp()
        
        
        paddle.y += paddle.velocity
        paddle.moveTo(paddle.x,paddle.y)
        

class Evade:
    def state(self,args):
        ball = args['ball']
        paddle = args['paddle']
        
        #if the ball is on it's way back towards the enemy paddle
        #pop off the Evade state.  This brings us back to our Chase
        #state most of the time.  For all intents and purposes, our
        #state machine is just a stack. ;)
        
        if ball.x > 170: paddle.state.pop()
        
        if ball.y > (paddle.y+20):  #if ball is below paddle
            if (ball.y - (paddle.y+20)) > 70:   #if ball is over 200 pixels away
                paddle.vDown()  #then move towards the ball
                
        elif ball.y < (paddle.y+20):    #if ball is above paddle
            if ((paddle.y+20) - ball.y) > 70:   #if the ball is over 200 pixels away
                paddle.vUp()    #then move towards the ball
        
        
        paddle.y += paddle.velocity
        paddle.moveTo(paddle.x,paddle.y)


class Shoot:
    def state(self,args):
        ball = args['ball']
        paddle = args['paddle']
        player = args['player']
        
        #if the ball is coming back at the enemy paddle, pop this
        #state off the state machine.
        if ball.x < 170: paddle.state.pop()
        
        
        if player.y > paddle.y: #if the player is below the paddle
            if (player.y - paddle.y) > 70:  #if the player is over 200 pixels away
                paddle.vDown()  #Move the paddle down
                
        elif player.y < paddle.y:   #if the player is above the paddle
            if (paddle.y - player.y) > 70:  #if the player is over 200 pixels away
                paddle.vUp()
        
        
        paddle.y += paddle.velocity
        paddle.moveTo(paddle.x,paddle.y)
